<template>
	<view class="page-wrap" :data-theme="theme" :style="globalColor.style">
		<header-custom title="新高考选科" />
		<u-sticky bgColor="#fff">
		<u-tabs :current="tabIndex" :list="analyzeList" keyName="combName" @click="onTabChange"
			lineColor="#00C15D"></u-tabs>
		</u-sticky>
		<view class="space-block"></view>
		<view class="scroll-view-item" v-for="(item, index) in dataList.list" :key="index">
			<school-module v-if="options.tag == 'school'" :info="item" />
			<major-module v-if="options.tag == 'major'" :info="item" />
		</view>
		<u-loadmore :status="dataList.loading"></u-loadmore>
	</view>
</template>

<script>
	import headerCustom from '@/pagesBKS/components/header-custom.vue';
	import SchoolModule from '@/pagesBKS/components/school-module.vue';
	import MajorModule from '@/pagesBKS/components/major-module.vue';

	import {
		analysisList,
		analysisSchool,
		analysisMajor
	} from '@/api/bks.examinee.js'
	export default {
		components: {
			headerCustom,
			MajorModule,
			SchoolModule
		},
		data() {
			return {
				theme: 'bks-theme',
				globalColor: getApp().globalData.globalColor,
				tabIndex: 0,
				activeTab: 'XKZH0002',
				analyzeList: [
					// {combId: "XKZH0002", combName: "物理 化学 思政", schoolNum: 1692, majorNum: 1504, isFavorite: true}
				],
				blueColor: {
					'0%': '#6871FE',
					'100%': '#68D5FE',
				},
				orangeColor: {
					'0%': '#F7C34A',
					'100%': '#FE8F68',
				},
				dataList: {
					list: [
						// {
						//   id: 1,
						//   logo: 'https://bks.obs.cn-north-4.myhuaweicloud.com:443/setting/bks-logo.png',
						//   schoolName: '备考生备考生备考生备考生备考生备考生备考生备考生备考生备考生备考生',
						//   tags: ['重庆', '本科', '综合'],
						//   popularity: '12222222'
						// }
					],
					page: 1,
					size: 10,
					count: 0,
					loading: 'none'
				},
				options:{}
			}
		},
		onLoad(options) {
			if (options.id) {
				this.options = options
				this.activeTab = options.id
			}
			this._analysis()
		},
		onReachBottom: function() {
			this._reachBottom()
		},
		methods: {
			onTabChange(e) {
				this.tabIndex = e.index
				this.activeTab = e.combId
				this._initData()
				this._request()
			},
			// 提示
			tipsClick() {
				uni.showModal({
					showCancel: false,
					confirmColor: '#00C15D',
					content: '本数据来源于重庆市教育考试院发布的《2021年拟在渝招生普通高校招生专业(类)选考科目要求(3+1+2模式)_本科》、《2021年拟在渝招生普通高校招生专业(类)选考科目要求(3+1+2模式)_专科》通知的数据统计，具体请参考对应的考试院通知文件。'
				})
			},
			// 选科分析
			_analysis() {
				analysisList({ schoolType: this.options.activeTab }).then(res => {
					res.data.filter((item, index) => {
						const num = item.majorNum + item.schoolNum
						item.dx = (Math.round(item.schoolNum / num * 10000) / 100.00)
						item.zy = (Math.round(item.majorNum / num * 10000) / 100.00)
						if(this.options.id == item.combId){
							this.tabIndex = index
						}
					})
					this.analyzeList = res.data
					this._request()
				})
			},
			_request() {
				// 已经没有数据了
				if (this.dataList.loading == 'not') {
					return
				}
				// 加载更多数据
				const {
					dataList: {
						list,
						page,
						size
					},
					options: { tag, activeTab }
				} = this
				this.dataList.loading = 'loading'
				const fu = tag == 'school' ? analysisSchool : analysisMajor
				let reqData = {
					"combId": this.analyzeList[this.tabIndex].combId,
					"campusType": activeTab,
					page,
					size
				}
				fu(reqData).then(res => {
					const total = res.data.pageInfoVO.total
					const countList = [...list, ...res.data.list]
					this.dataList.list = countList
					this.dataList.count = total
					if (countList.length >= total && total > 0 || total <= 0) {
						this.dataList.loading = 'nomore'
					} else {
						this.dataList.loading = 'loading'
					}
				}).catch(err => {
					console.log(err)
					this.dataList.loading = 'nomore';
				})
			},
			_initData() {
				this.dataList = {
					list: [],
					page: 1,
					size: 10,
					count: 0
				}
			},
			_reachBottom() {
				if (this.dataList.size * this.dataList.page < this.dataList.count) {
					this.dataList.loading = 'loading';
					this.dataList.page++;
					this._request();
				} else {
					this.dataList.loading = 'nomore';
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>